package com.service.single.example.expiringmap;

import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;

import java.util.concurrent.TimeUnit;

/**
 * @Author: 一休
 * @DateTime: 2022/11/16 09:29
 */
public class Expiringmap {

    /**
     * 可设置过期时间的map
     * 相同的key 不会覆盖
     */
    public static void main(String[] args) {
        ExpiringMap<String, String> map = ExpiringMap.builder().variableExpiration().expirationPolicy(ExpirationPolicy.CREATED).build();
        map.put("key", "value", 10, TimeUnit.SECONDS);
        map.put("key","tong",5,TimeUnit.SECONDS);
        try {
            Thread.sleep(5000);
            System.out.println(map.getExpectedExpiration("key"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
